package com.taldh.utils.assertutils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.helpers.MessageFormatter;

import java.util.Collection;

@Slf4j
public enum AssertUtils {

    ;

    public static void isNotNull(Object obj, String msg, Object ...pars) {
        if (obj == null) {
            throw new RuntimeException(MessageFormatter.arrayFormat(msg, pars).getMessage());
        }
    }

    public static void isTrue(Boolean isTrue, String msg, Object ...pars) {
        if (isTrue == null || !isTrue) {
            throw new RuntimeException(MessageFormatter.arrayFormat(msg, pars).getMessage());
        }
    }

    public static void isNotBlank(String str, String msg, Object ...pars) {
        if (StringUtils.isBlank(str)) {
            throw new RuntimeException(MessageFormatter.arrayFormat(msg, pars).getMessage());
        }
    }

    public static void isNotEmpty(Collection<?> collection, String msg, Object ...pars) {
        if (collection == null || collection.isEmpty()) {
            throw new RuntimeException(MessageFormatter.arrayFormat(msg, pars).getMessage());
        }
    }

    public static void isNatureNumber(int num, String msg, Object ...pars) {
        if (num < 0) {
            throw new RuntimeException(MessageFormatter.arrayFormat(msg, pars).getMessage());
        }
    }

}
